package com.lu.library.kv

import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

class KVDelegate<T>(

    private val model: MMKVImpl = MMKVImpl(),
    private val key:String,
    private val def:T?=null):ReadWriteProperty<Any?,T> {

    override fun getValue(thisRef: Any?, property: KProperty<*>): T {
        return model.get(key,def as Any) as T
    }

    override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
        model.put(key,value as Any)
    }
}